package com.dds.system.service.union.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.dds.common.config.AppInterfaceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dds.system.mapper.union.UnionShopContractMapper;
import com.dds.system.domain.union.UnionShopContract;
import com.dds.system.service.union.IUnionShopContractService;

/**
 * 店铺的合同记录Service业务层处理
 *
 * @author gaolianjie
 * @date 2021-04-26
 */
@Service
public class UnionShopContractServiceImpl implements IUnionShopContractService {
    @Autowired
    private UnionShopContractMapper unionShopContractMapper;

    @Autowired
    private AppInterfaceConfig appInterfaceConfig;

    /**
     * 查询店铺的合同记录
     *
     * @param id 店铺的合同记录ID
     * @return 店铺的合同记录
     */
    @Override
    public UnionShopContract selectUnionShopContractById(Integer id) {
        return unionShopContractMapper.selectUnionShopContractById(id);
    }

    /**
     * 查询店铺的合同记录列表
     *
     * @param unionShopContract 店铺的合同记录
     * @return 店铺的合同记录
     */
    @Override
    public List<UnionShopContract> selectUnionShopContractList(UnionShopContract unionShopContract) {
        return unionShopContractMapper.selectUnionShopContractList(unionShopContract);
    }

    /**
     * 新增店铺的合同记录
     *
     * @param unionShopContract 店铺的合同记录
     * @return 结果
     */
    @Override
    public int insertUnionShopContract(UnionShopContract unionShopContract) {
        return unionShopContractMapper.insertUnionShopContract(unionShopContract);
    }

    /**
     * 修改店铺的合同记录
     *
     * @param unionShopContract 店铺的合同记录
     * @return 结果
     */
    @Override
    public int updateUnionShopContract(UnionShopContract unionShopContract) {
        return unionShopContractMapper.updateUnionShopContract(unionShopContract);
    }

    /**
     * 批量删除店铺的合同记录
     *
     * @param ids 需要删除的店铺的合同记录ID
     * @return 结果
     */
    @Override
    public int deleteUnionShopContractByIds(Integer[] ids) {
        return unionShopContractMapper.deleteUnionShopContractByIds(ids);
    }

    /**
     * 删除店铺的合同记录信息
     *
     * @param id 店铺的合同记录ID
     * @return 结果
     */
    @Override
    public int deleteUnionShopContractById(Integer id) {
        return unionShopContractMapper.deleteUnionShopContractById(id);
    }

    @Override
    public List<String> selectUnionShopContractByShopId(String shopId) {
        List<Map<String, Object>> contractList = unionShopContractMapper.selectUnionShopContractByShopId(shopId);
        List<String> data = new ArrayList<>();

        for (Map<String, Object> contract : contractList) {
            data.add(appInterfaceConfig.getImgUrl() + contract.get("contract_url").toString());
        }

        return data;
    }
}
